//
//  Extension+UIBarButtonItem.swift
//  SHWeibo
//
//  Created by jingming wang on 16/7/20.
//  Copyright © 2016年 cpy.name. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(title: String? = nil, imgName: String? = nil, target: AnyObject?, action: Selector) {
        self.init()
        
        let btn = UIButton()
        
        if let _title = title {
            btn.setTitle(_title, forState: .Normal)
            btn.setTitleColor(K_THEME_COLOR, forState: .Normal)
            btn.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Disabled)
            btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        }
        
        if let _imgName = imgName {
            btn.setImage(UIImage(named: _imgName), forState: .Normal)
        }
        
        //添加点击监听
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        btn.sizeToFit()
        self.customView = btn
    }
}